
function openCollapse(strID, iheightMax) {
    $(strID).style.overflow = "hidden";
    if ($(strID).className.indexOf("hide") != -1) {
        $(strID).style.display = "none";
        $(strID).removeClassName('hide');
    }
    if ($(strID).style.display != "none") {
        $(strID).style.height = iheightMax + "px";
        scrollLock(strID, iheightMax);
    } else {
        $(strID).style.height = 0 + "px";
        scrollUnLock(strID, iheightMax);
    }
}

function scrollLock(strID, iheightMax) {
    var i = parseInt($(strID).style.height) - 7;
    $(strID).style.height = (i <= 7 ? 7 : i) + "px";
    if (parseInt($(strID).style.height) - 7 <= 7) {
        $(strID).style.height = "";
        $(strID).style.display = "none";
    } else {
        setTimeout("scrollLock('" + strID + "'," + iheightMax + ");", 13);
    }
}
function scrollUnLock(strID, iheightMax) {
    $(strID).style.display = "block";
    $(strID).style.height = (parseInt($(strID).style.height) + 7) + "px";
    if (parseInt($(strID).style.height) >= iheightMax) {
        $(strID).style.height = "";
    } else {
        setTimeout("scrollUnLock('" + strID + "'," + iheightMax + ");", 13);
    }
}

// ham set cookie khi dang nhap
function SetCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
};
//ham Get Cookie khi load form dang nhap
function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) return (getCookieVal(j));
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return (null);
};
function IsNumeric(input) {
    return (input - 0) == input && input.length > 0;
}
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return (unescape(document.cookie.substring(offset, endstr)));
};
// xoa cookie khi user dang nhap ma ko check vao checkbox
function DeleteCookie(name, path) {
    if (GetCookie(name)) {
        document.cookie = name + "=" + path + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
};
// kiem tra email do user nhap vao
function checkMail(str) {
    var filter = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
    var rtn = filter.test(str);
    return rtn;
};


// kiem tra ky tu dac biet
function ClickRegExpChar(str) {
    var filter = /^([a-zA-Z0-9_])+$/;
    var rtn = filter.test(str);
    if (rtn == false)
        return false;
    else
        return true;
};
//ham kiem tra ky tu unicode
function checkUnicode(str) {
    str = str.toLowerCase();
    var n = str.length;
    for (var i = 0; i < n; i++) {
        if (str.charCodeAt(i) > 222) { return false; } //tra ve chuoi co chua ky tu unicode
    }
    return true;
};

function resizeBox() {
    try {
        if ($('div_ShowPopup')) {
            var box = $('div_ShowPopup');
            if (box && box.visible()) {
                var sizeW = utils.windowSize();
                //var boxL = (sizeW[0] - box.getDimensions().width) / 2;
                var boxT = (sizeW[1] - box.getDimensions().height + 10) / 2;
                //boxL = (boxL > 0 ? boxL : 0);
                boxT = (boxT > 0 ? boxT : 15);
                //box.style.left = boxL + 'px';
                box.style.top = boxT + 'px';
            }
        }
    }
    catch (ex) { }
    if ($("div_BodyMain")) {
        $("div_BodyMain").style.width = $("div_Body").offsetWidth + "px";
    }
    if ($("div_Shadow")) {
        $("div_Shadow").style.height = $("div_BodyMain").offsetHeight + 'px';
        $("div_Shadow").style.width = $("div_BodyMain").offsetWidth + 'px';
    }
    //else if ($("div_Shadow")) $("div_Body").style.width = window.innerWidth;
}
function loadTextboxEvent(container) {
    //textbox
    var arr = container.select('.txtSigninPopup');
    arr.invoke('observe', 'click', textboxFocus);
    var arrTextbox = container.select('input', 'textarea');
    if (arrTextbox.length > 0) {
        arrTextbox.invoke('observe', 'focus', textboxFocus);
        arrTextbox.invoke('observe', 'blur', textboxBlur);
        if (!arrTextbox[0].visible()) arrTextbox[0].focus();
    }
};
//set focus cho text box
function textboxFocus(e) {
    var ele = Event.element(e);
    if (!ele.hasClassName('txtSigninPopup')) ele = ele.up('.txtSigninPopup');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    };

    ele.addClassName('txtfocus');
};
function textboxBlur(e) {
    var ele = Event.element(e);
    var tagName = ele.tagName;
    var isBackground = true;
    if (tagName == 'INPUT' && ele.value != '')
        isBackground = false;
    if (!ele.hasClassName('txtSigninPopup')) ele = ele.up('.txtSigninPopup');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    }
};
/*load focus cho Login Thanh Toan*/

function loadTextboxEventSI(container) {
    //textbox
    var arr = container.select('.div_txtSI');
    arr.invoke('observe', 'click', textboxFocusSI);
    var arrTextbox = container.select('input');
    if (arrTextbox.length > 0) {
        arrTextbox.invoke('observe', 'focus', textboxFocusSI);
        arrTextbox.invoke('observe', 'blur', textboxBlurSI);
        if (!arrTextbox[0].visible()) arrTextbox[0].focus();
    }
};
//set focus cho text box
function textboxFocusSI(e) {
    var ele = Event.element(e);
    if (!ele.hasClassName('div_txtSI')) ele = ele.up('.div_txtSI');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    };

    ele.addClassName('txtfocus');
};
function textboxBlurSI(e) {
    var ele = Event.element(e);
    var tagName = ele.tagName;
    var isBackground = true;
    if (tagName == 'INPUT' && ele.value != '')
        isBackground = false;
    if (!ele.hasClassName('div_txtSI')) ele = ele.up('.div_txtSI');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    }
};


/*load focus cho box thanh toan*/

function loadTextboxEventTT(container) {
    //textbox
    var arr = container.select('.div_txtDKTT');
    arr.invoke('observe', 'click', textboxFocusTT);
    var arrTextbox = container.select('input', 'textarea');
    if (arrTextbox.length > 0) {
        arrTextbox.invoke('observe', 'focus', textboxFocusTT);
        arrTextbox.invoke('observe', 'blur', textboxBlurTT);
        if (!arrTextbox[0].visible()) arrTextbox[0].focus();
    }
};
//set focus cho text box
function textboxFocusTT(e) {
    var ele = Event.element(e);
    if (!ele.hasClassName('div_txtDKTT')) ele = ele.up('.div_txtDKTT');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    };

    ele.addClassName('txtfocus');
};
function textboxBlurTT(e) {
    var ele = Event.element(e);
    var tagName = ele.tagName;
    var isBackground = true;
    if (tagName == 'INPUT' && ele.value != '')
        isBackground = false;
    if (!ele.hasClassName('div_txtDKTT')) ele = ele.up('.div_txtDKTT');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    }
};
/* End load focus cho box thanh toan*/
function loadTextboxEventDN(container) {
    //textbox
    var arr = container.select('.textTraLoi');
    arr.invoke('observe', 'click', textboxFocusDN);
    var arrTextbox = container.select('input', 'textarea');
    if (arrTextbox.length > 0) {
        arrTextbox.invoke('observe', 'focus', textboxFocusDN);
        arrTextbox.invoke('observe', 'blur', textboxBlurDN);
        if (!arrTextbox[0].visible()) arrTextbox[0].focus();
    }
};
//set focus cho text box
function textboxFocusDN(e) {
    var ele = Event.element(e);
    if (!ele.hasClassName('textTraLoi')) ele = ele.up('.textTraLoi');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    };

    ele.addClassName('txtfocus');
};
function textboxBlurDN(e) {
    var ele = Event.element(e);
    var tagName = ele.tagName;
    var isBackground = true;
    if (tagName == 'INPUT' && ele.value != '')
        isBackground = false;
    if (!ele.hasClassName('textTraLoi')) ele = ele.up('.textTraLoi');
    if (!ele) return;
    var el = ele.up().down('.txtfocus');
    if (el) {
        el.removeClassName('txtfocus');
    }
};
//connvert toi kieu tien te
function format_number(pnumber, decimals) {
    if (isNaN(pnumber)) { return 0 };
    if (pnumber == '') { return 0 };

    var snum = new String(pnumber);
    var sec = snum.split('.');
    var whole = parseFloat(sec[0]);
    var result = '';

    if (sec.length > 1) {
        var dec = new String(sec[1]);
        dec = String(parseFloat(sec[1]) / Math.pow(10, (dec.length - decimals)));
        dec = String(whole + Math.round(parseFloat(dec)) / Math.pow(10, decimals));
        var dot = dec.indexOf('.');
        if (dot == -1) {
            dec += '.';
            dot = dec.indexOf('.');
        }
        while (dec.length <= dot + decimals) { dec += '0'; }
        result = dec;
    } else {
        var dot;
        var dec = new String(whole);
        dec += '.';
        dot = dec.indexOf('.');
        while (dec.length <= dot + decimals) { dec += '0'; }
        result = dec;
    }
    return result;
}
function ConvertToMoney(theValue) {
    theValue = theValue.toString();
    var strNew = "";
    var iLength = theValue.length;
    var iFlag = 0;
    if (theValue.length > 3) {
        for (var i = 1; i <= iLength; i++) {
            strNew = theValue.substring(iLength - i, iLength - i + 1) + strNew;
            if (iFlag == 2) {
                strNew = (i + 1 > iLength ? "" : ".") + strNew;
                iFlag = 0;
            } else iFlag++;
        }
    }
    else {
        strNew = theValue;
    }
    return strNew;
}
function trim(str) {
    str = str.replace(/\s+/g, '');
    return str;
}
function checkPhone(str) {
    var filter = /^([0-9\,])+$/;
    var rtn = filter.test(str);
    if (rtn == false)
        return false;
    else
        return true;
}

function checkMoney(str) {
    var filter = /^([0-9])+$/;
    var rtn = filter.test(str);
    if (rtn == false)
        return false;
    else
        return true;
}

/* Modified to support Opera */
function bookmarksite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}
function showCity() {
    var strParam = window.location.href.toQueryParams("&");
    var strState_1 = "";
    try {
        strState_1 = strParam.st;
    } catch (ex) { }
    var strHTML = '';
    strHTML = '<select  runat="Server" id="ddlCityNew" name="ddlCityNew" autocomplete="off" class="ddlDWBirth">';
    for (var i = 0; i < langCity()[0].length; i++) {
        strHTML += '<option value="' + langCity()[0][i] + '" ' + (strState_1 == langCity()[0][i] ? 'selected="selected"' : '') + '>' + langCity()[1][i] + '</option>';
    }
    strHTML += '</select>';
    $("dDDLNew").innerHTML = strHTML;
    /*edit here 11/01/2011*/
    if ($("ddlCityNew")) {
        var ddlTinhNew = new ddlDD();
        ddlTinhNew.initializeCtrl('ddlCityNew', onLoadDDL, onChangeCities, true);
    }
    /*end*/
}
function setUrlByCity() {
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', ''); 
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    var strParam = window.location.href.toQueryParams("&");
    var strState_1 = "";
    var strYahoo = window.location.href.toLowerCase().indexOf('/yahoo/') != -1 ? '/yahoo/' : '';
    try {
        strState_1 = strParam.st;
    } catch (ex) { }
    strState_1 = checkState(strState_1);
    strState_1 = (strState_1.length > 0 ? "?st=" + strState_1 : "");
    if ($('aGiaoHang')) {
        $('aGiaoHang').href = strUrlLink + "thanhtoan.aspx";
        $('aChuyenKhoan').href = strUrlLink + "thanhtoan.aspx";
        $('aPayoo').href = strUrlLink + "thanhtoan.aspx";
        $('aCardVN').href = strUrlLink + "thanhtoan.aspx";
        $('aCardQT').href = strUrlLink + "thanhtoan.aspx";
    }
    if ($('liBMuaChung')) {
        $('liBMuaChung').select("a").each(function(obj) {
            if ($(obj).href.indexOf("javascript") == -1)
                $(obj).href == $(obj).href + strState_1;
        });
    }
    if ($("div_BodyMain")) {
        $("div_BodyMain").down(".div_LogoTop1").href = strUrlLink;
        $("div_BodyMain").down(".dLogo_Yahoo").href = strUrlLink;

        if ($("div_BodyMain").down(".ulListTG")) {
            $("div_BodyMain").down(".ulListTG").select('a').each(function(obj) {
                if ($(obj).href.indexOf("javascript") == -1)
                    $(obj).href == $(obj).href + strState_1;
            });
        }
    }
}
function checkState(str) {
    switch (str) {
        case "tp-ho-chi-minh": case "ha-noi": case "can-tho":
            return str;
            break;
        default:
            return "";
            break;
    }
}
function convertStateToID(str) {
    switch (str) {
        case "tp-ho-chi-minh":
            return 8;
            break;
        case "ha-noi":
            return 4;
            break;
        case "can-tho":
            return 710;
            break;
        default:
            return 8;
            break;
    }
}
/*function setStateForUrl() {
if (window.location.href.toLowerCase().indexOf('/profile/') == -1) {
$('div_aTabMenu').childNodes[0].href = "index.aspx?st=" + GetCookie("stateCity");
$('div_aTabMenu').childNodes[1].href = "recentDeals.aspx?st=" + GetCookie("stateCity");
$('div_aTabMenu').childNodes[2].href = "TraiNghiem.aspx?st=" + GetCookie("stateCity");
}
}*/
function setDivHotPhone() {
    if (strStateNM.toLowerCase() == "tp-ho-chi-minh") {      
        if ($("div_hotPhone")) {
            $("div_hotPhone").innerHTML = '<p class="color3 styleText1" ><strong>HotLine:</strong><strong class="styleText3"> 08 7305 6616</strong></p>' +
                        '<a href="ymsgr:sendim?hotro_nhommuahcm2" style="float: left; margin-left: 4px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotro_nhommuahcm2&amp;m=g&amp;t=2" /></a>' +
                        '<a href="ymsgr:sendim?hotro_nhommuahcm" style="float: left; margin-left: 3px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotro_nhommuahcm&amp;m=g&amp;t=2" /></a>';
        }                        
    }
    else if (strStateNM.toLowerCase() == "ha-noi") {                     
        if ($("div_hotPhone")) {
            $("div_hotPhone").innerHTML = '<p class="color3 styleText1" ><strong>HotLine:</strong><strong class="styleText3"> 04 7305 6616</strong></p>' +
                        '<a href="ymsgr:sendim?hotro_nhommua_hanoi" style="float: left; margin-left: 4px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotro_nhommua_hanoi&amp;m=g&amp;t=2" /></a>' +
                        '<a href="ymsgr:sendim?hotro_nhommua" style="float: left; margin-left: 3px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotro_nhommua&amp;m=g&amp;t=2" /></a>';
        }
    }
    else if (strStateNM.toLowerCase() == "can-tho") {
        if ($("div_hotPhone")) {
            $("div_hotPhone").innerHTML = '<p class="color3 styleText1" ><strong>HotLine:</strong><strong class="styleText3"> 08 7305 6614</strong></p>' +
                            '<a href="ymsgr:sendim?hotronhommua_cantho" style="float: left; margin-left: 4px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotronhommua_cantho&amp;m=g&amp;t=2" /></a>' +
                            '<a href="ymsgr:sendim?hotronhommua_cantho1" style="float: left; margin-left: 3px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotronhommua_cantho1&amp;m=g&amp;t=2" /></a>';
        }
    }
    else if (strStateNM.toLowerCase() == "hai-phong") {
        if ($("div_hotPhone")) {
            $("div_hotPhone").innerHTML = '<p class="color3 styleText1" ><strong>HotLine:</strong><strong class="styleText3"> 031 730 6616</strong></p>' +
                            '<a href="ymsgr:sendim?hotronhommua_hp1" style="float: left; margin-left: 4px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotronhommua_hp1&amp;m=g&amp;t=2" /></a>' +
                            '<a href="ymsgr:sendim?hotronhommua_hp2" style="float: left; margin-left: 3px; padding-top: 7px;"><img width="125" height="25" border="0" src="http://opi.yahoo.com/online?u=hotronhommua_hp2&amp;m=g&amp;t=2" /></a>';
        }
    }

}
function showDropDownForMobile() {
    if (navigator.userAgent.toLowerCase().indexOf("mobile") == -1 && navigator.userAgent.toLowerCase().indexOf("ipad") == -1 && navigator.userAgent.toLowerCase().indexOf("ipod") == -1 && navigator.userAgent.toLowerCase().indexOf("samsung") == -1 && navigator.userAgent.toLowerCase().indexOf("symbian") == -1) {

    }
    else {
        $("div_BodyMain").select(".select_small").each(function(obj) {
            $(obj).style.display = "none";
            $(obj).parentNode.down("select").style.display = "block";
            $(obj).parentNode.down("select").style.width = $(obj).style.width;
        });
    }
}
//var api = null;
//function loadMap() {
//    api = new EBMap("divMap", 673, 504);
//    api.clickLogo(true);
//    api.uInfBox();
//    api.setLogo("http://www.nhommua.com/images/iconMap.png", 45, 46);
//    api.initAPI();
//    api.aZoom = new Array(0.0244, 0.0488, 0.0976, 0.1953, 0.3906,
//    0.7812, 1.5625, 3.125, 6.25, 12.5, 25, 50, 100);
//    api.addTypeControl(MAP_POS_RIGHTTOP, 20, 20);
//    api.addZoomControl(20, 20);
//    //api.setMapByAddress(123, 'truong dinh', 'P.7', 'Q.10', 8);
//    $('aUpdatePos').onclick = updateLocation;
//    $('btnGetPosition').onclick = getLocation;

//    //edit by Nam 07/04/2011
//    //onChangeCitiesLocal("ddlPosCity", "8");
//    var iCityID = 8;
//    if (getQueryStringValue("CityID") != "")
//        iCityID = parseInt(getQueryStringValue("CityID"));

//    $("ddlPosCity").value = iCityID;
////    if ($("ddlPosCity")) {
////        var CityPos = new ddlDD();
////        CityPos.initializeCtrl('ddlPosCity', onLoadDDL, onChangeCitiesLocal, true);
////    }
//   // onChangeCitiesLocal("ddlPosCity", iCityID);
//    //edit by Nam 07/04/2011
//    // $('btnGetPosition').observe('click', function() {
//    //   api.setMapByAddress('123', 'ly chinh thang', 'P.5', 'Q.3', 8);
//    //    alert(api.savePosition());
//    //});
//}
